//
//  User.m
//  ClienteHabitueIOS
//
//  Created by Mauro Carreño on 5/29/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "User.h"
#import "ControlVariables.h"
#import "Math.h"
#import "DataLoader.h"

@implementation User


@synthesize externalId;
@synthesize name;
@synthesize surname;
@synthesize employeeId;
@synthesize traderMKT;


- (void) dealloc
{
    [externalId release], externalId = nil;
    [name release], name = nil;
    [surname release], surname = nil;
    [employeeId release], employeeId = nil;
    [super dealloc];
}


- (id) initWithDictionary:(NSDictionary*)dictionary
{
    self = [super init];
    self.externalId = (![DataLoader isNull:[dictionary objectForKey:@"id"]]) ? [dictionary objectForKey:@"id"] : @"";
    self.name = (![DataLoader isNull:[dictionary objectForKey:@"name"]]) ? [dictionary objectForKey:@"name"] : @"";
    self.surname = (![DataLoader isNull:[dictionary objectForKey:@"surname"]]) ? [dictionary objectForKey:@"surname"] : @"";
    self.employeeId = (![DataLoader isNull:[dictionary objectForKey:@"employeeId"]]) ? [dictionary objectForKey:@"employeeId"] : @"";
    self.traderMKT = (![DataLoader isNull:[dictionary objectForKey:@"fromTradeMkt"]]) ? [[dictionary objectForKey:@"fromTradeMkt"] boolValue ]: false;
    
    return self;
}

- (NSString*) toJSON
{
    return [NSString stringWithFormat:@"{\"id\":\"%@\",\"user\":\"%@\"}",self.externalId, self.name];

}



@end
